//
//  GridBootcamp.swift
//  swiftUiTest
//
//  Created by Mac on 2023/6/28.
//

import SwiftUI

struct GridBootcamp_17: View {
    
    let columns:[GridItem] = [
        GridItem(.fixed(150),spacing: nil,alignment: nil),
        GridItem(.fixed(150),spacing: nil,alignment: nil),
        GridItem(.fixed(150),spacing: nil,alignment: nil),
        GridItem(.fixed(150),spacing: nil,alignment: nil),
        GridItem(.fixed(150),spacing: nil,alignment: nil)
    ]
    
    let columns2:[GridItem] = [
        GridItem(.flexible(),spacing: 6),
        GridItem(.flexible(),spacing: 6),
        GridItem(.flexible(),spacing: 6),
        GridItem(.flexible(),spacing: 6)
    ]
    
    let column3:[GridItem] = [
        GridItem(.adaptive(minimum: 50,maximum: 300)),
        GridItem(.adaptive(minimum: 150,maximum: 300)),
    ]
    
    
    
    var body: some View {
        ScrollView{
            
            LazyVGrid(
                columns:columns2,
                alignment:.center,
                spacing: 6,
                pinnedViews: [.sectionHeaders],
                content: {
                    Section(header:
                                Text("Section 1")
                        .foregroundColor(.white)
                        .font(.title)
                        .frame(maxWidth: .infinity,alignment: .leading)
                        .background(Color.blue)
                        .padding()
                    ) {
                        ForEach(0..<20) { index in
                            Rectangle()
                                .frame(height: 150)
                        }
                    }
                    
                    Section(header:
                                Text("Section 2")
                        .foregroundColor(.white)
                        .font(.title)
                        .frame(maxWidth: .infinity,alignment: .leading)
                        .background(Color.red)
                        .padding()
                    ) {
                        ForEach(0..<20) { index in
                            Rectangle()
                                .fill(Color.gray)
                                .frame(height: 150)
                                
                        }
                    }
                    
                    Section(header:
                                Text("Section 3")
                        .foregroundColor(.white)
                        .font(.title)
                        .frame(maxWidth: .infinity,alignment: .leading)
                        .background(Color.green)
                        .padding()
                    ) {
                        ForEach(0..<20) { index in
                            Rectangle()
                                .frame(height: 150)
                        }
                    }
                    
                }
               
            )
            
//            Rectangle()
//                .fill(Color.white)
//                .frame(height: 400)
//
//            LazyVGrid(columns: columns2) {
//                ForEach(0..<50) { index in
//                    Rectangle()
//                        .frame(height: 150)
//                }
//            }
        }
    }
}

struct GridBootcamp_Previews: PreviewProvider {
    static var previews: some View {
        GridBootcamp_17()
    }
}
